package _interview75;

/**
 * 1004. 最大连续1的个数 III
 */
public class No1004 {
    public int longestOnes(int[] nums, int k) {
        int answer = 0;

        for (int left = 0, right = 0; right < nums.length; ) {
            if (nums[right] == 1) {
                right++;
            } else if (k > 0) {
                right++;
                k--;
            } else if (nums[left++] == 0) k++;

            answer = Math.max(right - left, answer);
        }
        return answer;
    }
}
